<?php
	include_once("DataProvider.php");
	include_once("../DTO/loaiTaiKhoanDTO.php");
	
	class loaiTaiKhoanDAO
	{
		public $sql="";
		var $loaiTaiKhoanDTO;
		
		function __construct()
		{
			return $this->loaiTaiKhoanDTO = new loaiTaiKhoanDTO();
		}
		
		public function load()
		{
			$result= DataProvider::ExecuteQuery($this->sql);
			$arrLoaiTaiKhoanDTO = new ArrayObject();
			
			while($row = mysql_fetch_array($result))
			{
				$loaiTaiKhoanDTO = new loaiTaiKhoanDTO();
				$loaiTaiKhoanDTO->idLoaiTaiKhoan = $row['idLoaiTaiKhoan'];
				$loaiTaiKhoanDTO->tenLoaiTaiKhoan = $row['tenLoaiTaiKhoan'];
				$loaiTaiKhoanDTO->giaLoaiTaiKhoan =$row['giaLoaiTaiKhoan'];
				$loaiTaiKhoanDTO->duocBan =$row['duocBan'];
				$loaiTaiKhoanDTO->giaBan1SP =$row['giaBan1SP'];
				$loaiTaiKhoanDTO->duocMua =$row['duocMua'];
				$loaiTaiKhoanDTO->giaMua1SP =$row['giaMua1SP'];
				$loaiTaiKhoanDTO->biXoa =$row['biXoa'];
				
				$arrLoaiTaiKhoanDTO[] = $loaiTaiKhoanDTO;
			}
			return $arrLoaiTaiKhoanDTO;
		}
		
		public function load_All()
		{
			$this->sql= 'select * from loaiTaikhoan';
			$result=$this->load();
			return $result; 
		}
		
		public function load_One($idLoaiTaiKhoan)
		{
			$this->sql = 'select * from loaiTaiKhoan where idLoaiTaiKhoan ='.$idLoaiTaiKhoan;
			$result = $this->load();
			return $result;
		}
		
		public function load_LoaiTaiKhoan()
		{
			$this->sql = 'select * from loaiTaiKhoan where biXoa=0';
			$result = $this->load();
			return $result;
		}
		
		
		public function themLoaiTK($tenLoaiTaiKhoan)
		{
			$this->sql = 'insert into loaiTaiKhoan values(NULL,"'.$tenLoaiTaiKhoan.'")';
			$result = DataProvider::ExecuteQuery($this->sql);
			return $result;
		}
		
		public function suaLoaiTK($tenLoaiTK, $tenLoaiTaiKoan)//$tenLoaiTK: ten cu, $tenLoaiTaiKoan: ten moi, can update vo
		{
			$this->sql = 'update loaiTaiKhoan set tenLoaiTaiKhoan="'.$tenLoaiTaiKoan.'" where tenLoaiTaiKhoan="'.$tenLoaiTK.'"';
			$result = DataProvider::ExecuteQuery($this->sql);
			return $result;
		}
		
		public function xoaLoaiTK($idLoaiTaiKhoan)
		{
			$this->sql = 'update loaiTaiKhoan set biXoa=1 where idLoaiTaiKhoan="'.$idLoaiTaiKhoan.'"';
			$result = DataProvider::ExecuteQuery($this->sql);
			return $result;
		}
		
		public function layTenLoaiTaiKhoan($idLoaiTK)
		{
			$sql="select * from loaiTaiKhoan where idLoaiTaiKhoan = ".$idLoaiTK;
			$result=DataProvider::ExecuteQuery($sql);
			$row = mysql_fetch_array($result);
			$loaiTaiKhoanDTO = new loaiTaiKhoanDTO();
			$loaiTaiKhoanDTO->tenLoaiTaiKhoan = $row['tenLoaiTaiKhoan'];
			$arrLoaiTaiKhoan = new ArrayObject();
			$arrLoaiTaiKhoan[] = $loaiTaiKhoanDTO;
			return $arrLoaiTaiKhoan;
		}
	}
	
?>

